package com.hivekion.workflow.service.impl;

import com.hivekion.common.exception.BusinessException;
import com.hivekion.workflow.service.ProTaskService;
import org.activiti.engine.TaskService;
import org.activiti.engine.task.Task;
import org.activiti.engine.task.TaskQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProTaskServiceImpl implements ProTaskService {

      @Autowired
      TaskService taskService;

      @Override
      public List<Task> getCheckTodo(String user) {

	    TaskQuery query = taskService.createTaskQuery().orderByTaskCreateTime().desc();
	    return query.list();
      }

      @Override
      public boolean complete(String taskId) {
	    Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
	    if (task == null) {
		  throw new BusinessException(500, "未找到对象");
	    }
	    taskService.complete(taskId);
	    return false;
      }
}
